#include<stdio.h>
#include<stdlib.h>
typedef struct number
{
    int data;
    struct number *ptr;
}num;

num*  addnum(num *head,int adddata )
{
    num *current=head;
    num *add=(num*)malloc(sizeof(num));
    if(head==NULL)
    {
        head=add;
    }
   else
   {
        while(current->ptr!=NULL)
        {
            current=current->ptr;
        }
        current->ptr=add;
    }
    add->data=adddata;
    add->ptr=NULL;
    return head;
}

void nummatch(num *heada,num *headb)
{
    int flag=0,headdata=headb->data;
    num *currentb=headb,*currenta=heada;
    while(heada&&!flag)
    {
        if(heada->data==headdata)
        {
            currentb=headb;
            currenta=heada;
            while(currentb&&currenta)
            {
                if(currentb->data!=currenta->data)
                {
                    break;
                }
                else{
                    currenta=currenta->ptr;
                    currentb=currentb->ptr;
                }
            }
            if(!currentb)
            {
                flag=1;
            }else{
                heada=heada->ptr;
            }
            
        }
        else{
            heada=heada->ptr;
        }
    }
    if(flag==1)
    {
        printf("ListB is the sub sequence of ListA.");
    }else{
        printf("ListB is not the sub sequence of ListA.");
    }
}
void delenum(num *head)
{
    num*current=head;
    while(current->ptr!=NULL)
    {
        current=current->ptr;
        free(head);
        head=current;
    }
}


int main()
{
    int a,count,b;
    num* heada=NULL,*headb=NULL;
    while(1)
    {
        scanf("%d",&a);
        if(a==-1)
        {
            break;
        }
        else{
           heada=addnum(heada,a);
        }
    }
    while(1)
    {
        scanf("%d",&b);
        if(b==-1)
        {
            break;
        }
        else{
           headb=addnum(headb,b);
        }
    }
    num* tempa=heada;
    nummatch(heada,headb);
    
    delenum(tempa);
    delenum(headb);

    return 0;
}